
import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('BuildControl')
export class BuildControl extends Component {

    @property(Node) build1: Node = null!;
    @property(Node) build2: Node = null!;
    @property(Node) playerNode: Node = null!;
    private buildCount = 1; //记录角色跑过了多少地图块

    start() {
        // [3]
    }

    update(dt: number) {
        let playerNodePos = this.playerNode.getPosition();
        if (this.buildCount % 2 == 1) {
            let build1Pos = this.build1.getPosition();
            //角色跑到了第-块地图上 120是第一块地图的长度
            if (playerNodePos.z > (build1Pos.z + 120)) {
                console.log('跑超了第一块地图')
                this.build1.setPosition(0, 0, (this.buildCount + 1) * 120);

                this.buildCount++;
            }
        } else {
            let build2Pos = this.build2.getPosition();
            //角色跑到了第二块地图上 120是第二块地图的长度

            if (playerNodePos.z > (build2Pos.z + 120)) {
                console.log('跑超了第二块地图')
                this.build2.setPosition(0, 0, (this.buildCount + 1) * 120);

                this.buildCount++;
            }
        }


    }
    //无限循环地图节点



}


